package com.zxk.service.impl;

import com.sun.jna.platform.win32.WinDef;
import com.zxk.constant.JNAConstants;
import com.zxk.constant.ParamConstants;
import com.zxk.constant.PicConstants;
import com.zxk.enums.Coord;
import com.zxk.service.AbstractMyTask;
import com.zxk.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 使用活力任务
 *
 * @author: 舟小亢
 * @date: 2023-08-27 15:09
 */
public class UseEnergyTaskImpl extends AbstractMyTask {

    private static Logger LOG = LoggerFactory.getLogger(UseEnergyTaskImpl.class);

    public UseEnergyTaskImpl(WinDef.HWND hwnd_0, WinDef.HWND hwnd_1, WinDef.HWND hwnd_2) {
        super(hwnd_0, hwnd_1, hwnd_2);
    }

    @Override
    public String getTaskName() throws Exception {
        return "使用活力";
    }

    @Override
    public boolean execute() throws Exception {
        LOG.warn("【使用活力任务】开始！");

        // 点击人物头像
        MouseUtil.lClickRandom(hwnd_1, Coord.ROLE_LOCATION.getX(), Coord.ROLE_LOCATION.getY());

        // 查找并点击使用
        if (!FuzzyPicUtil.findAndClickRandom(hwnd_0, hwnd_1, PicConstants.使用活力任务_使用)) {
            return false;
        }

        // 循环查找并点击打工
        for (int i = 0; i < 15; i++) {
            if (!FuzzyPicUtil.findAndClickRandom(hwnd_0, hwnd_1, PicConstants.使用活力任务_打工)) {
                return false;
            }
        }

        // 退出当前界面
        KeyUtil.kClick(hwnd_1, JNAConstants.VK_ESCAPE);
        KeyUtil.kClick(hwnd_1, JNAConstants.VK_ESCAPE);

        LOG.warn("【使用活力任务】结束！");
        return true;
    }

}
